﻿using System;
using System.Linq;
using System.Collections.Generic;

using Ah.Testudin.Engine.Events;

using Microsoft.Xna.Framework;

namespace Ah.Testudin.Engine.Actors.Components.Collision
{
    public class CollisionHandlerComponentComposite : ActorComponentBase, ICollisionHandlerComponent
    {
        #region Private Member Variables

        private readonly IEnumerable<ICollisionHandlerComponent> _collisionHandlers;

        #endregion

        #region Constructors

        public CollisionHandlerComponentComposite(
            Actor owner,
            IEventManager eventManager,
            IEnumerable<ICollisionHandlerComponent> collisionHandlers)
            : base(owner, eventManager)
        {
            if (collisionHandlers == null)
            {
                throw new ArgumentNullException("collisionHandlers");
            }

            _collisionHandlers = collisionHandlers;
        }

        #endregion

        #region ActorComponentBase

        public override void Update(GameTime gameTime)
        {
        }

        public override void Dispose()
        {
            foreach (ICollisionHandlerComponent currentComponent in _collisionHandlers)
            {
                currentComponent.Dispose();
            }
        }

        #endregion

        #region ICollisionHandlerComponent
    
        public void HandleCollision()
        {
            foreach (ICollisionHandlerComponent currentCollisionHandlerComponent in _collisionHandlers)
            {
                currentCollisionHandlerComponent.HandleCollision();
            }
        }

        #endregion
    }
}